'''
用来存放自定义公共工具的
'''
from flask import current_app
from flask import g
from flask import session

from info.models import User
import functools


def numb_to_eng(numb):
    if numb ==1:
        return 'first'
    elif numb ==2:
        return 'second'
    elif numb ==3:
        return 'third'
    else:
        return ''


#用装饰器获取用户登录状态
def get_user_cookie(func):
    @functools.wraps(func)
    def inner(*args,**kwargs):
        user_id = session.get('user_id')
        user = None
        # 判空,如果不是空的，则执行代码
        if user_id:
            try:
                user = User.query.get(user_id)
            except Exception as e:
                current_app.logger.error(e)
        g.user = user
        return func(*args,**kwargs)
    return inner